#include <stdio.h>

int main()
{
    int limit, t, units, u, f, d, i;
    char s[100];
    fgets(s, sizeof(s), stdin);
    sscanf(s, "%d %d %d %d %d", &limit, &units, &u, &f, &d);
    t = 0;
    for (i = 0; i < units; i++)
    {
        fgets(s, sizeof(s), stdin);
        if (s[0] == 'f')
            t += 2 * f;
        else
            t += (u + d);
        if (t > limit)
            break;
    }
    printf("%d\n", i);
    return 0;
}
